import importlib
import inspect
from typing import Any


def is_function_or_coroutine(obj: Any) -> bool:
    '''
    判断函数是协程函数还是普通函数
    :param obj:
    :return:
    '''
    return inspect.isfunction(obj) or inspect.iscoroutinefunction(obj)


def is_callable_instance(obj: object) -> bool:
    # 判断对象是否包含有__call__的方法重写
    return hasattr(obj, "__call__") and not isinstance(obj, type)


def create_exc_instance(
        exc_class: type[Exception], exc_args: list[Any] | None = None
) -> Exception | None:
    '''
    创建一次对象实例
    :param exc_class:
    :param exc_args:
    :return:
    '''
    importlib.import_module(exc_class.__module__)
    value = exc_class(*exc_args) if exc_args else exc_class()
    return value if isinstance(value, Exception) else None
